<?php

/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/5/1
 * Time: 21:45
 */
class wTest extends Controller
{

    /**
     * 生成大量订单
     */
    public function generateOrders() {
        set_time_limit(0);
        $this->loadModel(['mOrder', 'User']);
        $cartData = [
            [
                'pid' => 8092,
                'spid' => 0,
                'count' => mt_rand(1, 5)
            ]
        ];
        $addrData = json_decode('{"proviceFirstStageName":"广东","addressCitySecondStageName":"广州市","addressCountiesThirdStageName":"天河区","addressDetailInfo":"新燕花园三期1201 新燕花园三期1201 新燕花园三期1201 新燕花园三期1201","addressPostalCode":510006,"telNumber":18565518404,"userName":"陈永才","Address":"广东广州市天河区新燕花园三期1201 新燕花园三期1201 新燕花园三期1201 新燕花园三期1201","err_msg":"edit_address:ok"}', true);
        if (!$cartData || sizeof($cartData) == 0) {
            return $this->echoMsg(-1, '订单数据非法');
        }
        if (empty($addrData)) {
            return $this->echoMsg(-1, '地址数据非法');
        }
        for ($i = 0; $i < 999; $i++) {
            try {
                $orderId = $this->mOrder->create('o_JvCuFQoYqbwIWOSPnrDkRP6Wrg', $cartData, $addrData, [
                    'remark' => $this->post('remark'),
                    'exptime' => $this->post('exptime'),
                    'balancePay' => $this->post('balancePay') == 1,
                    'expfee' => $this->post('expfee'),
                    'envsid' => intval($this->post('envsId')),
                    'status' => 'received',
                    'wepay_serial' => uniqid()
                ]);
                $this->echoMsg(0, intval($orderId));
            } catch (Exception $ex) {
                $this->log('order_create_error:' . $ex->getMessage());
                $this->echoMsg(-1, $ex->getMessage());
            }
        }
    }

    /**
     * 测试订单返佣
     */
    public function testRebate() {
        $this->loadModel(['OrderRebate', 'User']);
        $this->OrderRebate->rebate(360);
        $this->OrderRebate->rebate(361);
        $this->OrderRebate->rebate(362);
    }

}